<template>
  <div>
    <el-dialog
      title="选择报修单"
      :visible.sync="dialogTableVisible"
      :close-on-click-modal="false"
      width="900px">
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="维修单号" >
          <el-input
            v-model="queryParams.code"
            placeholder="请输入维修单号"
            clearable
            size="small"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="">搜索</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="loading" :data="list" stripe
                @selection-change="chanpinonChange" >
        <el-table-column align="center" type="selection" width="55"></el-table-column>
        <el-table-column align="center" type="index" label="序号"  width="55"  />
        <el-table-column align="center" label="维修单号" property="oddNumber" width="150" ></el-table-column>
        <el-table-column align="center" label="报修人"   property="repairsUserName" :show-overflow-tooltip="true"  ></el-table-column>
        <el-table-column align="center" label="故障类型" property="typeName" :show-overflow-tooltip="true" width="150" ></el-table-column>
        <el-table-column align="center" label="故障等级"  property="faultState" width="100" ></el-table-column>
        <el-table-column align="center" label="报修时间"  property="theRepairTime" width="100" ></el-table-column>
        <el-table-column align="center" label="负责人"  property="chargeUserName" width="100" ></el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="1"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        style="margin-top: 15px"
        :total="total">
      </el-pagination>


      <span slot="footer" class="dialog-footer">
        <el-button type="primary"  size="mini" @click="determine">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import { treeselect } from "@/api/system/dept";
  import {repairxunList} from '@/api/repair/index'
  export default {
    props: ['routerData'],
    name: "Role",
    data() {
      return {
        loading:false,
        dialogTableVisible:true,
        //产品查询数据
        queryParams:{
         
        },
        newxuanz:[],//当前选中的
        deptOptions:[],//树形图数据
        defaultProps: {
          children: "children",
          label: "label"
        },
        list:[],
        total:0
      };
    },
    components:{

    },
    watch: {
      dialogTableVisible: function () {
        this.dialogTableVisible = true;//始终让他为true;
        this.cancel();//隐藏
      },
    },
    created() {
      console.log('接受',this.routerData)
      this.queryParams.deviceId=this.routerData
      this.getTreeselect();//树形图查询
      this.getList()
    },
    methods: {
      getList(){
        repairxunList(this.queryParams).then((res)=>{
          if(res.code==200){
            this.list=res.rows
            this.total=res.total
          }
        })
      },
      //确定
      determine:function(){

        this.$emit('callback',this.newxuanz)//将submitModel的值传给父组件
      },
      //隐藏
      cancel:function(){
        this.determine()

      },
      /** 查询部门下拉树结构 */
      getTreeselect() {
        treeselect().then(response => {
          this.deptOptions = response.data;
        });
      },
      //产品表格监听
      chanpinonChange(val) {
        console.log(val)
        this.newxuanz = val
      },
      //分页
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
      },
      // 筛选节点
      filterNode(value, data) {
        if (!value) return true;
        return data.label.indexOf(value) !== -1;
      },
      // 节点单击事件
      handleCheckChange(data, checked, indeterminate) {
        var rad=''
        var ridsa = this.$refs.tree.getCheckedKeys().join(',')// 获取当前的选中的数据[数组] -id, 把数组转换成字符串
        var ridsb = this.$refs.tree.getCheckedNodes()// 获取当前的选中的数据{对象}
        ridsb.forEach(ids=>{//获取选中的所有的父级id
          rad+=','+ids.id
        })
        rad=rad.substr(1) // 删除字符串前面的','
        var rids=rad+','+ridsa
        var arr=rids.split(',')//  把字符串转换成数组
        arr=[...new Set(arr)]; // 数组去重
        console.log('arr',arr)
        rids=arr.join(',')// 把数组转换成字符串
        console.log(rids)
      },


    }
  };
</script>
<style >





</style>
